

function say() {
    alert("LC:264. 丑数 II");
}
say();


//参考
https://leetcode-cn.com/problems/ugly-number-ii/solution/leetcodeti-jie-264-chou-shu-iisan-zhi-zh-2bur/


/**
 * @param {number} n
 * @return {number}
 */
var nthUglyNumber = function(n) {
    //9:23-38
    
    //3:10-25

    var uglyArr = [1]

    var idx2 = 0
    var idx3 = 0
    var idx5 = 0
    for(var i = 1; i < n; i++){
        var ugly2 = uglyArr[idx2] * 2
        var ugly3 = uglyArr[idx3] * 3
        var ugly5 = uglyArr[idx5] * 5

        var min = Math.min(ugly2, ugly3, ugly5)
        uglyArr.push(min)

        if(ugly2 == min){
            idx2 ++
        }
        if(ugly3 == min){
            idx3 ++
        }
        if(ugly5 == min){
            idx5 ++
        }
    }

    return uglyArr.pop()

};
